package com.jojo.jojoWorld.service.impl;

import com.baomidou.mybatisplus.extension.exceptions.ApiException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jojo.jojoWorld.entity.Jojo;
import com.jojo.jojoWorld.mapper.JojoMapper;
import com.jojo.jojoWorld.service.JojoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * JojoServiceImpl
 *
 * @author byc
 * @date 2021-09-22
 */
@Service
public class JojoServiceImpl extends ServiceImpl<JojoMapper,Jojo> implements JojoService {

    @Override
    public List<Jojo> findAll() {
        return baseMapper.findAll();
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delFlag(int[] ids) {
        for (int id : ids) {
            Jojo jojo = getById(id);
            int delFlag = jojo.getDelFlag();
            if (delFlag == 1) {
                throw new ApiException("不存在，没得删。");
            }else {
            baseMapper.delFlag(id);
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void del(int id) {
        Jojo jojo = getById(id);
        int delete = jojo.getDelFlag();
        if (delete == 1){
            throw new ApiException("没了，删不了");
        }
        baseMapper.deleteById(id);
    }


}
